#define _CRT_SECURE_NO_WARNINGS 1
/**
*      author: Y_Yao
*      created: 2024-09-23 18:33:52
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
const int N = 1000 + 5;
LL a[N];
LL sum[N];
int n, c;
LL ret;

void dfs(int i, LL ans)
{
    if (ans > c) return;
    if (sum[i - 1] + ans <= c)
    {
        ret = max(ret, sum[i - 1] + ans);
        return;
    }

    ret = max(ans, ret);

    for (int j = i - 1;j > 0;j--)
    {
        dfs(j, ans + a[j]);
    }
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> c;
    for (int i = 1;i <= n;i++)
    {
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    dfs(n + 1, 0);
    cout << ret << endl;
    return 0;
}